<?php
namespace Pay\Controller;

class UserController extends CommonController {
    const SESSION_NAME = 'userinfo';

    protected function _initialize(){

    }

    public function Login(){
        $uid = (int)I('post.uid');
        if( $uid > 0){
            //获取用户信息
            $db = zyt_data_init();
            //用户基本信息
            $user = $db->getUserInfo($uid)[0];
            //用户资金信息
            $capital = $db->getUserCapital($uid)[0];
            if( $user['user_id'] == $uid ){
                $data['user_id']    = $user['user_id'];
                $data['user_name']  = $user['user_name'];
                $data['user_phone'] = $user['user_phone'];
                $data['user_email'] = $user['user_email'];
                $data['user_tb']    = floatval(number_format($capital['tong_money_count'], 2, '.', ''));
                $data['user_ye']    = floatval(number_format($capital['consumed_money_count'], 2, '.', ''));

                //写入SESSION
                session(self::SESSION_NAME, $data);
                $this->ajaxReturn($data);
            }else{
                $this->Logout();
            }
        }else{
            $this->Logout();
        }
    }

    public function Logout(){
        session(self::SESSION_NAME, null); //删除SESSION
    }

    public function notice(){
        $ref = I('get.ref');
        $token = I('get.Token');
        if(substr($ref, -5, 5) === '.html'){
            $ref = substr($ref, 0, -5);
        }
        $this->Login($token);
        header("Location:$ref");
    }


}